<?php

    if(!defined("__XE__")) exit();

    if(false || $called_position == 'before_module_proc') {

		// 팝업 내용 정리
		function getPopupScript($val) {

			if($val->content) {
				$order = array("\r\n", "\n", "\r");
				$replace = '';
				$val->content = str_replace($order, $replace, $val->content);
			}

			return "	jQuery('<div></div>').xe_popup({id:'".$val->popup_srl."'"
				.($val->popup_type?",popup_type:'".$val->popup_type."'":"")
				.($val->content?",content:'".$val->content."'":"")
				.($val->popup_url?",url:'".$val->popup_url."'":"")
				.($val->popup_link?",link:'".$val->popup_link."'":"")
				.($val->popup_link_type?",link_type:'".$val->popup_link_type."'":"")
				.($val->open_type?",open_type:'".$val->open_type."'":"")
				.($val->top?",top:'".$val->top."px'":"")
				.($val->left?",left:'".$val->left."px'":"")
				.($val->width?",width:'".$val->width."px'":"")
				.($val->height?",height:'".$val->height."px'":"")
				.($val->exp_days?",exp_days:'".$val->exp_days."'":"")
				."});"."\n";
		}

		// 팝업 띄우기
		function popupOpen($popupList) {

				Context::addJsFile('./addons/popup_opener/popup_opener.js');

				$addPopupScript = '<script type="text/javascript">//<![CDATA['."\n";
				$addPopupScript .= 'jQuery(function(){'."\n";

				if($popupList) {					
					if(!is_array($popupList)) $popupList = array($popupList);

					foreach($popupList as $val){
						$addPopupScript .= getPopupScript($val);
					}
				}

				$addPopupScript .= '});'."\n";
				$addPopupScript .= '//]]></script>'."\n";
				Context::addHtmlHeader($addPopupScript);
 		}

		// module_srl 값이 없는 경우와 관리자 모듈에서는 실행하지 않음
		if($this->module_info->module != 'admin' && $this->module_info->module_srl) {

			// 사이트 확인
            $args->site_srl = $this->module_info->site_srl;
            $output = executeQuery('module.getSite', $args);
			$domain = $output->data->domain;

			// 모듈이 지정된 팝업 띄우기
			$oPopupAdminModel = &getAdminModel('popup');
			$targets->module_srl = $this->module_info->module_srl;
			$popupList = $oPopupAdminModel->getPopupForThisSrl($targets);

			if($popupList) popupOpen($popupList);

			// popup 모듈이 선택된 내용은 모든 모듈에서 팝업 띄우기
			$oModuleModel = &getModel('module');
			$targets->module_srl = $oModuleModel->getModuleSrlByMid('popup');
			$popupAllList = $oPopupAdminModel->getPopupForThisSrl($targets);

			if($popupAllList) popupOpen($popupAllList);
		}
    }
?>